package com.xp.basic.heima.nio.work;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.nio.charset.Charset;

/**
 * 使用新api实现的bio 客户端
 */
public class NioClientWithMsg {


    public static void main(String[] args) throws IOException {
        SocketChannel sc = SocketChannel.open();
        //这里是直接使用客户端连接
        sc.connect(new InetSocketAddress(8080));

        //连接上之后就发消息过去
        ByteBuffer byteBuffer = Charset.defaultCharset().encode("和loop大大简化");
        sc.write(byteBuffer);

        System.in.read();

    }
}
